package com.xlh.controller;
import com.alibaba.fastjson.JSON;
import com.xlh.domain.Order;
import com.xlh.domain.Product;
import com.xlh.service.OrderService;
import com.xlh.service.ProductService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cloud.client.discovery.DiscoveryClient;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.client.RestTemplate;

//@RestController
@Slf4j
public class OrderController2 {
    @Autowired
    private OrderService orderService;
    @Autowired
    private ProductService productService;
    //下单测试4  通过feign调用
    @GetMapping("/order/prod/{pid}")
    public Order order(@PathVariable("pid") Integer pid) {
        log.info(">>客户下单，这时候要调用商品微服务查询商品信息");
        Product product = productService.findByPid(pid);
        log.info(">>商品信息,查询结果:" + JSON.toJSONString(product));
        //模拟一次网络延时
       /* try {
            Thread.sleep(2000);
        } catch (InterruptedException e) {  e.printStackTrace();
        }*/
        Order order = new Order();
        order.setUid(1);
        order.setUsername(" 测 试 用 户 ");
        order.setPid(product.getPid());
        order.setPname(product.getPname());
        order.setPprice(product.getPprice());
        order.setNumber(1);
        //为了不产生大量垃圾数据  暂时不做订单保存操作
        //orderService.createOrder(order);
        return  order;
    }
    //测试高并发
    @RequestMapping("/order/message")
    public String message() {
        return "测试高并发";
    }
}
